package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 创建索引类型
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum CreateEsIndexEnum {

  /** 门类 */
  ARCHIVE_TYPE(1, "按门类"),
  /** 全宗 */
  FONDS(2, "按全宗");

  private Integer code;
  private String desc;

  public static CreateEsIndexEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到档案状态：" + type));
  }

  @JsonCreator
  public static CreateEsIndexEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
